import { FormSchema, BasicColumn } from "/@/components/Table"
import { DescItem } from "/@/components/Description/index"
import { render } from "/@/utils/common/renderUtils"
import { UploadBizType } from "/@/enums/uploadEnum"
import { Input } from "ant-design-vue"
import { h } from "vue"
export const MaterialType = {
  IMAGE: { type: "image", name: "图片" },
  VOICE: { type: "voice", name: "音频" },
  VIDEO: { type: "video", name: "视频" },
}

export const getUploadBizType = (materialType) => {
  if ("image" === materialType) {
    return UploadBizType.GENERAL_IMAGE
  }
  if ("video" === materialType) {
    return UploadBizType.GENERAL_VIDEO
  }
  if ("voice" === materialType) {
    return UploadBizType.GENERAL_VOICE
  }
}

export const columns: BasicColumn[] = [
  {
    title: "名称",
    dataIndex: "url",
    slots: { customRender: "media" },
    width: 240,
    align: "left",
  },
  {
    title: "大小",
    dataIndex: "size",
    customRender: ({ text }) => {
      return render.renderSpan(text + " KB")
    },
    width: 80,
  },
  {
    title: "创建时间",
    dataIndex: "createdAt",
    width: 150,
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "name",
    label: "",
    component: "Input",
    componentProps: {
      placeholder: "搜索媒体",
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "bizType",
    label: "业务类型",
  },
  {
    field: "bucketName",
    label: "存储桶",
  },
  {
    field: "storageType",
    label: "存储器",
    render: (curVal, data) => {
      return render.renderTag(render.renderDict(curVal, "file_storage_type"), "green")
    },
  },
  {
    field: "originalName",
    label: "文件原始名称",
  },
  {
    label: "新文件名",
    labelMinWidth: 50,
    field: "newName",
  },
  {
    field: "fileTypeName",
    label: "文件类型",
  },
  {
    field: "fileSize",
    label: "文件大小",
    render: (curVal, data) => {
      return render.renderTag(curVal + " KB", "green")
    },
  },
  {
    field: "filePath",
    label: "存储绝对路径",
  },
  {
    field: "createdAt",
    label: "创建时间",
  },
  {
    field: "createdBy",
    label: "创建者",
  },
]

export const materialGroupFormSchema: FormSchema[] = [
  {
    label: "id",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    field: "name",
    label: "分组名称",
    component: "Input",
    required: true,
  },
  {
    field: "parentId",
    label: "上级分组",
    component: "TreeSelect",
    required: false,
  },
  {
    field: "sortNo",
    label: "排序",
    required: true,
    component: "InputNumber",
    defaultValue: 1,
  },
  {
    field: "remark",
    label: "备注",
    component: "InputTextArea",
    componentProps: {
      autoSize: {
        minRows: 3,
        maxRows: 8,
      },
    },
  },
]

export const materialFormSchema: FormSchema[] = [
  {
    label: "id",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: "materialType",
    field: "materialType",
    component: "Input",
    show: false,
  },
  {
    label: "",
    field: "originUrl",
    component: "Input",
    show: false,
  },
  {
    label: "",
    field: "urlSign",
    component: "Input",
    show: false,
  },

  {
    field: "name",
    label: "名称",
    component: "Input",
    required: true,
  },
  {
    field: "url",
    component: "MyUpload",
    slot: "uploadFild",
    label: "媒体文件",
  },
  {
    field: "groupId",
    label: "分组",
    component: "TreeSelect",
    required: false,
    componentProps: {
      fieldNames: {
        title: "name",
        key: "id",
        value: "id",
      },
      dropdownStyle: {
        maxHeight: "60vh",
      },
      getPopupContainer: (node) => node.parentNode,
    },
  },
  {
    field: "httpUrl",
    component: "Input",
    label: "链接",
    render: ({ model, field }) => {
      return h(Input, { value: model["originUrl"], readOnly: true })
    },
  },
]
